
$(function () {
    //判断是否可用
    getName();
    //注册
    getEnroll();
    //防止默认跳转
    getStop();
})




//文字移入
$("#site span").mouseenter(function () {
    $("#site .s_wz").css("color", "black");
});
$("#site span").mouseleave(function () {
    $("#site .s_wz").css("color", "");
});


//地域选择
let num = 0;
$("#site .s_china").on("click", function () {
    num++;
    if (num % 2 == 1) {
        $("#price").css("display", "block");
    } else {
        $("#price").css("display", "none");
    }
});
//背景替换
$("#price li").mouseenter(function () {
    $(this).css("background", "rgba(0, 0, 0, .03)").siblings("li").css("background", "#fff");
});
//内容替换
$("#price li").on("click", function () {
    $("#site .s_china").html($(this).html());
    $("#price").hide();
});


//密码框切换
let res = 0;
$("#code span").on("click", function () {
    res++;
    if (res % 2 == 1) {
        $(this).css("background-image", "url(../img/login/10026.png)");
        $("#code input").attr("type", "password");
    } else {
        $(this).css("background-image", "url(../img/login/10027.png)");
        $("#code input").attr("type", "text");
    }
});
//确认密码框切换
let counts = 0;
$("#Bank span").on("click", function () {
    counts++;
    if (counts % 2 == 1) {
        $(this).css("background-image", "url(../img/login/10026.png)");
        $("#Bank input").attr("type", "password");
    } else {
        $(this).css("background-image", "url(../img/login/10027.png)");
        $("#Bank input").attr("type", "text");
    }
});

//判断是否符合登录标准
//手机号
let regUser = /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[189]))\d{8}$/;
let flagUser = false;
//判断用户名是否规范并且数据库查找是否重复
function getName() {
    $('#username').on("blur", function () {
        if ($(this).val() == '') {
            alert("不能为空！")
        } else {
            if (regUser.test($(this).val())) {
                $('#user').html("√")
                $("#user").css("color", "green");
                flagUser = true;
                console.log(1);
                ajaxtool({
                    type: "get",
                    url: "../php/signinS.php",
                    data: "name=" + $('#username').val(),
                    success: function (data) {
                        console.log(data);
                        if (data.trim() == '1') {
                            alert('该用户名可用');
                        } else {
                            alert('该用户名不可用');
                        }
                    }
                })
            } else {
                $('#user').html("x")
                $("#user").css("color", "red");
                flagUser = false;
            }
        }
    })
}
//注册
function getEnroll() {
    $('#enter').on("click", function () {
        if ($("#userpass").val() == '' || $("#userpassS").val() == '') {
            alert("不能为空！")
        } else {
            console.log(1);
            ajaxtool({
                type: "post",
                url: "../php/signin.php",
                data: "name=" + $('#username').val() + "&pass=" + $('#userpass').val(),
                success: function (data) {
                    console.log(data);
                    if (data.trim() == 'success') {
                        alert('注册成功');
                        location.href = '../html/index.html';

                    } else {
                        alert('注册失败');
                    }
                }
            })
        }
    })
}
//阻止默认跳转
function getStop() {
    $("#enter").on("submit", function () {
        if (regPass && flagUser) {
            return true;//  运行跳转
        }
        return false; // 阻止跳转

    })
}


